<?php 
require_once("soap/nusoap.php");
$ns="http://store8x.com/webser/";
//$ns="http://localhost/vfun/";
$server = new soap_server();  
$server->configureWSDL('Service',$ns);
$server->wsdl->schemaTargetNamespace=$ns;  
$server->soap_defencoding = 'UTF-8'; 
$server->register('receiveMO',
	array(	'commandcode' => 'xsd:string',  //EX: WF, WORLD
    		'serviceid' => 'xsd:string', // Số dịch vụ (6x76)
    		'userid'=> 'xsd:string', //84902171891
    		'message'=> 'xsd:string', //ACC pass,KD nje
    		'requestid'=> 'xsd:string',//ID MO: randomcode: 298963647
    		'username'=> 'xsd:string', //authentication
    		'password'=> 'xsd:string'),//authentication	
	 array('result' => 'xsd:string'),  
		    $ns,                                                  
		    "$ns#receiveMO", 
		    'rpc',                        
		    'encoded',                    
		    'get MO'      
		    );

function receiveMO($commandcode,$serviceid,$userid,$message,$requestid,$username,$password){
return new soapval('return','xsd:string',getMO($commandcode,$serviceid,$userid,$message,$requestid,$username,$password));
}

if ( !isset( $HTTP_RAW_POST_DATA ) ) $HTTP_RAW_POST_DATA =file_get_contents( 'php://input' );
$server->service($HTTP_RAW_POST_DATA); 

function getMO($commandcode,$serviceid,$userid,$message,$requestid,$username,$password) {
	if($username == "south" && $password=="south.123!@#"){
		$con = mysql_connect("localhost","honeyhubby_ad8x","Xuanson270986!");
		if (!$con)
		  {
		  	die('Could not connect: ' . mysql_error());
		  }else{ 
			mysql_select_db("honeyhubby_store8x", $con); 
			$query= "INSERT INTO tbmos(dest, phone, content,created,telco,cmdcode,requestId) VALUES('".$serviceid."','".$userid."','".$message."','".$createdate."','".null."','".$commandcode."','".$requestid."')";
			  if (!mysql_query($query,$con))
			  {
			  	 mysql_close($con);
			  	 return "ban da sai cu phap";
			  }else{
			  	mysql_close($con);
				return $userid.' da dang ky thanh cong dich vu';
			  }
			
		  }
	}else {
		return "error";
	}
} 


?>
